# encoding: utf-8
from exts import db
from datetime import datetime
import shortuuid


# 轮播图模型
class BannerModel(db.Model):
    __tablename__ = 'banner'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(255), nullable=False)
    image_url = db.Column(db.String(255), nullable=False)
    link_url = db.Column(db.String(255), nullable=False)
    priority = db.Column(db.Integer, default=0)
    create_time = db.Column(db.DateTime, default=datetime.now)


# 板块模型
class BoardModel(db.Model):
    __tablename__ = 'board'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(30), nullable=False)
    desc = db.Column(db.String(100), nullable=False)
    create_time = db.Column(db.DateTime, default=datetime.now)


# 帖子模型
class PostModel(db.Model):
    __tablename__ = 'post'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(200), nullable=False)
    content = db.Column(db.Text, nullable=False)
    is_banned = db.Column(db.Integer, default=1)
    create_time = db.Column(db.DateTime, default=datetime.now)

    board_id = db.Column(db.Integer, db.ForeignKey('board.id'),nullable=False)
    author_id = db.Column(db.String(50), db.ForeignKey('front_user.id'), nullable=False)

    board = db.relationship('BoardModel', backref='posts')
    author = db.relationship('FrontUser', backref='posts')


# 记录加精帖子的模型
class HighlightPostModel(db.Model):
    __tablename__ = 'highlight_post'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    create_time = db.Column(db.DateTime, default=datetime.now)
    post_id = db.Column(db.Integer, db.ForeignKey('post.id'),nullable=False)

    post = db.relationship('PostModel', backref='highlight')


# 帖子评论模型
class CommentModel(db.Model):
    __tablename__ = 'comment'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    content = db.Column(db.Text, nullable=False)
    create_time = db.Column(db.DateTime, default=datetime.now)

    post_id = db.Column(db.Integer, db.ForeignKey('post.id'),nullable=False)
    author_id = db.Column(db.String(50), db.ForeignKey('front_user.id'), nullable=False)

    post = db.relationship('PostModel', backref='comments')
    author = db.relationship('FrontUser', backref='comments')


# 帖子阅读量计算模型
class ReadpostModel(db.Model):
    __tablename__ = 'readpost'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    post_id = db.Column(db.Integer, db.ForeignKey('post.id'),nullable=False)
    author_id = db.Column(db.String(50), db.ForeignKey('front_user.id'), nullable=False)
    create_time = db.Column(db.DateTime, default=datetime.now)

    post = db.relationship('PostModel', backref='readers')
    author = db.relationship('FrontUser', backref='readers')
